<?php
/**
 * ===============================================
 * 版权所有 2019-2050 青岛铁锤科技有限公司，并保留所有权利。
 * 网站地址: http://www.huaxianling.com
 * ===============================================
 * Author: Rag Hu
 * Created Time: 2019/6/29 13:40
 * Modified Time: 2019/6/29 13:40
 * Version: 2.0
 */

namespace App\Modules\MemberCard\Validators;


use Flower\Core\Repository\Contracts\ValidatorInterface;
use Flower\Core\Repository\Validator\LaravelValidator;

class MemberCardValidator extends LaravelValidator
{
	protected $rules = [
		ValidatorInterface::RULE_CREATE => [
			'card_num' => 'required|unique:member_card',
			'member_id' => 'required|numeric',
			'store_id' => 'required|numeric',
			'type_id' => 'required|numeric',
			'attribute' => 'required|numeric',
			'balance' => 'required_if:category,2|numeric',
			'count' => 'required_if:category,1|numeric',
			'name' => 'required|between:2,8',
			'sex' => 'required|numeric',
			'mobile' => array('required','regex:/^1[345678]{1}\d{9}$/'),
		],
		ValidatorInterface::RULE_UPDATE => [
			'card_num' => 'filled|unique:member_card',
			'member_id' => 'filled|numeric',
			'store_id' => 'filled|numeric',
			'type_id' => 'filled|numeric',
			'attribute' => 'filled|numeric',
			'balance' => 'filled|numeric',
			'count' => 'filled|numeric',
			'name' => 'filled|between:2,8',
			'sex' => 'filled|numeric',
			'mobile' => array('filled','regex:/^1[23456789]{1}\d{9}$/'),
		],
	];
	protected $messages = [
		'card_num.required' => '会员卡号不能为空',

		//        'card_num.numeric' => '会员卡号格式错误',
		//        unique
		'card_num.unique' => '会员卡号重复，请重提交新申请！',
		'member_id.required' => '用户id不能为空',
		'member_id.numeric' => '用户id格式错误',

		'store_id.required' => '店铺id不能为空',
		'store_id.numeric' => '店铺id格式错误',

		'type_id.required' => '卡类id不能为空',
		'type_id.numeric' => '卡类id格式错误',

		'attribute.required' => '卡类不能为空',
		'attribute.numeric' => '卡类格式错误',

		'name.required' => '姓名不能为空',
		'name.between' => '姓名请输入2-8个字符',

		'sex.required' => '性别不能为空',
		'sex.numeric' => '性别格式错误',

		'mobile.required' => '手机号不能为空',
		'mobile.regex' => '手机号码格式错误',

		'present.required_without' => '请选择会员卡赠额',
		'present.numeric' => '会员卡赠额格式错误',
		'present.min' => '会员卡赠额不能低于1元',
		'present.max' => '会员卡赠额不能高于99999元',


		'count.required_without' => '请选择会员卡次数',
		'count.numeric' => '会员卡次数格式错误',
		'count.min' => '会员卡次数不能低于1次',
		'count.max' => '会员卡次数不能高于99999次',


	];
}